﻿using AntUnion.FrameWork.Model.Models;
using AntUnion.FrameWork.Model.ModelsExt;
using AntUnion.FrameWork.Web.Extend;
using AntUnion.FrameWork.Web.Service;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using static AntUnion.FrameWork.Web.Service.AssetsServer;
using System.Collections.Generic;
using System;
using TencentCloud.Tcr.V20190924.Models;
using static AntUnion.FrameWork.Web.Service.ReportServer;

namespace AntUnion.FrameWork.Web.Controllers
{
    public class ReportsController : BaseController
    {
        #region 持仓

        /// <summary>
        /// 持仓
        /// </summary>
        /// <returns></returns>
        public IActionResult Position()
        {
            return View();
        }

        [HttpGet]
        public IActionResult GetPositionAction()
        {
            Result res = new Result();
            try
            {
                List<string> list = reportServer.GetPositionAction();
                res.Code = 0;
                res.Data = list;
                return new JsonResult(res);
            }
            catch (Exception ex)
            {
                res.Code = 1;
                res.Data = ex.Message;
            }
            return new JsonResult(res);
        }

        [HttpGet]
        public IActionResult GetPositionSymbol()
        {
            Result res = new Result();
            try
            {
                List<string> list = reportServer.GetPositionSymbol();
                res.Code = 0;
                res.Data = list;
                return new JsonResult(res);
            }
            catch (Exception ex)
            {
                res.Code = 1;
                res.Data = ex.Message;
            }
            return new JsonResult(res);
        }

        [HttpGet]
        public IActionResult GetPositionList(int page, int limit, string server, string group, int? login, string position, string symbol, string enPositionAction, string time)
        {
            ListResult res = new ListResult();
            try
            {
                int count = 0;
                CrmUserModel crmUserModel = GetSession<CrmUserModel>("CrmUser");
                List<PositionList> list = reportServer.GetPosition(page, limit, null, null, crmUserModel.Id, position, symbol, enPositionAction, time, out count);
                res.Code = 0;
                res.Count = count;
                res.Data = list;
                return new JsonResult(res);
            }
            catch (Exception ex)
            {
                res.Code = 1;
                res.Data = ex.Message;
            }
            return new JsonResult(res);
        }

        #endregion

        #region 交易

        /// <summary>
        /// 交易
        /// </summary>
        /// <returns></returns>
        public IActionResult Deal()
        {
            return View();
        }

        [HttpGet]
        public IActionResult GetDealAction()
        {
            Result res = new Result();
            try
            {
                List<string> list = reportServer.GetDealAction();
                res.Code = 0;
                res.Data = list;
                return new JsonResult(res);
            }
            catch (Exception ex)
            {
                res.Code = 1;
                res.Data = ex.Message;
            }
            return new JsonResult(res);
        }

        [HttpGet]
        public IActionResult GetDealSymbol()
        {
            Result res = new Result();
            try
            {
                List<string> list = reportServer.GetDealSymbol();
                res.Code = 0;
                res.Data = list;
                return new JsonResult(res);
            }
            catch (Exception ex)
            {
                res.Code = 1;
                res.Data = ex.Message;
            }
            return new JsonResult(res);
        }

        [HttpGet]
        public IActionResult GetDealEntryFlag()
        {
            Result res = new Result();
            try
            {
                List<string> list = reportServer.GetDealEntryFlag();
                res.Code = 0;
                res.Data = list;
                return new JsonResult(res);
            }
            catch (Exception ex)
            {
                res.Code = 1;
                res.Data = ex.Message;
            }
            return new JsonResult(res);
        }

        [HttpGet]
        public IActionResult GetDealList(int page, int limit, string server, string group, int? login, string order, string symbol, string dealAction, string entry, string time)
        {
            ListResult res = new ListResult();
            try
            {
                int count = 0;
                CrmUserModel crmUserModel = GetSession<CrmUserModel>("CrmUser");
                List<DealList> list = reportServer.GetDeals(page, limit, null, null, crmUserModel.Id, order, symbol, dealAction, entry, time, out count);
                res.Code = 0;
                res.Count = count;
                res.Data = list;
                return new JsonResult(res);
            }
            catch (Exception ex)
            {
                res.Code = 1;
                res.Data = ex.Message;
            }
            return new JsonResult(res);
        }

        #endregion

        #region 订单

        /// <summary>
        /// 订单
        /// </summary>
        /// <returns></returns>
        public IActionResult Order()
        {
            return View();
        }

        [HttpGet]
        public IActionResult GetEnOrderType()
        {
            Result res = new Result();
            try
            {
                List<string> list = reportServer.GetEnOrderType();
                res.Code = 0;
                res.Data = list;
                return new JsonResult(res);
            }
            catch (Exception ex)
            {
                res.Code = 1;
                res.Data = ex.Message;
            }
            return new JsonResult(res);
        }

        [HttpGet]
        public IActionResult GetOrderSymbol()
        {
            Result res = new Result();
            try
            {
                List<string> list = reportServer.GetOrderSymbol();
                res.Code = 0;
                res.Data = list;
                return new JsonResult(res);
            }
            catch (Exception ex)
            {
                res.Code = 1;
                res.Data = ex.Message;
            }
            return new JsonResult(res);
        }

        [HttpGet]
        public IActionResult GetOrderList(int page, int limit, string order, string symbol, string type, string time)
        {
            ListResult res = new ListResult();
            try
            {
                int count = 0;
                CrmUserModel crmUserModel = GetSession<CrmUserModel>("CrmUser");
                //List<dynamic> list = reportServer.GetOrders(page, limit, null, null, crmUserModel.Id, order, symbol, state, timeSetup, out count);
                List<OrderList> list = reportServer.GetOrders(page, limit, null, null, crmUserModel.Id, order, symbol, type, time, out count);
                res.Code = 0;
                res.Count = count;
                res.Data = list;
                return new JsonResult(res);
            }
            catch (Exception ex)
            {
                res.Code = 1;
                res.Data = ex.Message;
            }
            return new JsonResult(res);
        }

        #endregion
    }
}
